import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbpms.config.SpringConfig;
import com.dbpms.mapper.ChamberMapper;
import com.dbpms.mapper.StudentManageMapper;
import com.dbpms.pojo.ChamberInfo;
import com.dbpms.pojo.Chamberfloorinfo;
import com.dbpms.pojo.Chambertypeinfo;
import com.dbpms.pojo.StudentInfo;
import com.dbpms.service.IChamberService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class chamberTest {

    @Autowired
    private IChamberService chamberService;

    /**
     * 寝室信息修改 √
     */
    @Test
    public void testUpdate(){

        ChamberInfo info = new ChamberInfo();
        info.setChamberFloorId(1);
        info.setChamberHotelNumber("1233");
        info.setChamberFloor(1);
        info.setChamberTypeId(2);
        info.setChamberBed(6);
        info.setChamberId(27);

        boolean pd = chamberService.updateChamberInfo(info);
        System.out.println(" pd : "+pd);
    }
    /**
     * 删除寝室信息 √
     */
    @Test
    public void testDelete(){
        boolean pd;
//        try {
//            pd = chamberService.deleteChamberInfo(5);
//        }catch (Exception E){
//            pd = false;
//        }
        pd = chamberService.deleteChamberInfo(5);

        System.out.println(" pd : "+pd);
    }
    /**
     * 新增寝室信息 √
     */
    @Test
    public void testAdd(){
        ChamberInfo info = new ChamberInfo();
        info.setChamberFloorId(1);
        info.setChamberHotelNumber("421412");
        info.setChamberFloor(1);
        info.setChamberTypeId(2);
        info.setChamberBed(6);
        info.setChamberNumberOfPeople(0);

        boolean pd = chamberService.addChamberInfo(info);
        System.out.println(" pd : "+pd);
    }
    /**
     * 查询寝室信息 √
     */
    @Resource
    private ChamberMapper chamberInfoMapper;
    @Test
    public void testSelect(){

        // chamber_bed >chamber_number_of_people
//        QueryWrapper<ChamberInfo> wrapper = new QueryWrapper<ChamberInfo>()
//                .apply("chamber_bed >chamber_number_of_people");
//
//        List<ChamberInfo> infos = chamberInfoMapper.queryAllChtInfo(wrapper);
//        infos.forEach(System.out::println);

        // 分页
        Page<ChamberInfo> p = chamberService.page(Page.of(1,2));

//        List<ChamberInfo> infos = chamberInfoMapper.test(p);
//        infos.forEach(System.out::println);
    }
    /**
     * 查询寝室楼信息
     */
    @Test
    public void testSelectChamberFloor(){
        List<Chamberfloorinfo> infos = chamberService.queryAllChtFloorInfo();
        infos.forEach(System.out::println);
    }
    /**
     * 查询寝室类型信息
     */
    @Test
    public void testSelectChamberType(){
        List<Chambertypeinfo> infos = chamberService.queryChtTypeInfo();
        infos.forEach(System.out::println);
    }
    /**
     * 条件查询 - 获取查到的总数
     */
    @Test
    public void testSelectCount(){
        QueryWrapper<ChamberInfo> wrapper = new QueryWrapper<ChamberInfo>();

        wrapper.eq("chamber_floor_id",1); // 寝室楼id
        int count = (int) chamberService.count(wrapper);
        System.out.println(count);
    }
    @Resource
    private StudentManageMapper studentManageMapper;
    @Test
    public void test(){
        QueryWrapper<StudentInfo> wrapper = new QueryWrapper<StudentInfo>()
                .eq("st.student_chamber_id",3);

        List<StudentInfo> list = studentManageMapper.queryStdInfo_Page(null,wrapper);

        list.forEach(System.out::println);
    }
}
